package com.sskj.b70.p.fragment;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.CapitalDetailData;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.v.fragment.CapitalDetailsFragment;

/**
 * ProjectName：new_bfex
 * DESC: (类描述)
 * Created by 李岩 on 2018/7/11 0011
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class CapitalDetailsPresenter extends BasePresenter<CapitalDetailsFragment> {
    private int page = 1;

    /**
     * 充值记录
     *
     * @param assetId
     * @param isRefresh
     */
    public void getRechargeList(String assetId, String stockCode, String type, boolean isRefresh) {
        if (isRefresh) {
            page = 1;
        }
        httpService.czAndTx(assetId, stockCode, type, page)
                .execute(new JsonCallBack<HttpData<CapitalDetailData>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<CapitalDetailData>> response) {
                        HttpData<CapitalDetailData> httpListData = response.body();
                        if (httpListData.getData().getRes().size() > 0) {
                            page++;
                        }
                        mView.onRechargeRecordSuccess(httpListData.getData().getRes(), isRefresh);
                    }
                });
    }

    /**
     * 提币记录
     *
     * @param assetId
     * @param isRefresh
     */
    public void getWithdrawList(int assetId, boolean isRefresh) {
        if (isRefresh) {
            page = 1;
        }
        OkGo.<HttpData<CapitalDetailData>>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW_LIST)
                .params("mobile", MyAppLication.getMobile())
                .params("pid", assetId)
                .params("p", page)
                .execute(new JsonCallBack<HttpData<CapitalDetailData>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<CapitalDetailData>> response) {
                        HttpData<CapitalDetailData> httpListData = response.body();
                        if (httpListData.getData().getRes().size() > 0) {
                            page++;
                        }
                        mView.onWithdrawRecordSuccess(httpListData.getData().getRes(), isRefresh);
                    }
                });
    }

    /**
     * 其他资金记录
     *
     * @param assetId
     * @param isRefresh
     */
    public void getAssetRecordList(String assetId, String stockCode, boolean isRefresh) {
        if (isRefresh) {
            page = 1;
        }
        httpService.assetListDetail(assetId, stockCode, page)
                .execute(new JsonCallBack<HttpData<CapitalDetailData>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<CapitalDetailData>> response) {
                        HttpData<CapitalDetailData> httpListData = response.body();
                        if (httpListData.getData().getRes().size() > 0) {
                            page++;
                        }
                        mView.onAssetRecordSuccess(httpListData.getData().getRes(), isRefresh);
                    }
                });
    }

    /**
     * 其他资金记录
     *
     * @param assetId
     * @param isRefresh
     */
    public void getBalanceRecordList(boolean isRefresh) {
        if (isRefresh) {
            page = 1;
        }
        OkGo.<HttpData<CapitalDetailData>>post(HttpConfig.BASE_URL + HttpConfig.BALANCE_RECORD_LIST)
                .params("p", page)
                .execute(new JsonCallBack<HttpData<CapitalDetailData>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<CapitalDetailData>> response) {
                        HttpData<CapitalDetailData> httpListData = response.body();
                        if (httpListData.getData().getRes().size() > 0) {
                            page++;
                        }
                        mView.onAssetRecordSuccess(httpListData.getData().getRes(), isRefresh);
                    }
                });
    }
}
